package com.mlf.observer.demo;

import lombok.Data;

import java.util.ArrayList;
import java.util.List;

@Data
public class WeatherData implements Subjects {

    private List<Observerz> observerzs = new ArrayList<>();
    private float temperature;
    private float humidity;
    private float pressure;


    @Override
    public void registerObserver(Observerz observerz) {
        observerzs.add(observerz);
    }

    @Override
    public void removeObserver(Observerz observerz) {
        observerzs.remove(observerz);
    }

    @Override
    public void notifyObservers() {
        for (Observerz observerz : observerzs) {
            observerz.update(temperature, humidity, pressure);
        }
    }

    public void measurementsChanged() {
        notifyObservers();
    }
    public void setMeasurements(float temperature, float humidity, float pressure) {
        this.temperature = temperature;
        this.humidity = humidity;
        this.pressure = pressure;
        measurementsChanged();
    }
}
